<?php
	include_once "config/common.php";
	
	if($_POST['username']!=false){
		if($_POST['password']!=false){
			if($_POST['verifycode']==false){
				if(strtolower($_POST['verifycode'])==strtolower($_COOKIE['verifycode'])){
					$sql = "admin where name='".$_POST['username']."'";
					$rs = $commonc->getList($sql);
					$rs = $rs['result']['0'];

					if($rs['id']!=''){
						if(md5($_POST['password'])==$rs['pwd']){
							$arr = array("last_login"=>date("Y-m-d H:i:s"));
							$commonc->update("admin",$arr,"id='".$rs['id']."'");
							setcookie("admin_id",$rs['id']);
							$commonc->refreshto('index.php','登录成功','1');
							
						}else{
							$commonc->refreshto('login.php','密码错误','1');
						}
					}else{
						$commonc->refreshto('login.php','用户不存在','1');
					}
				}else{
					$commonc->refreshto('login.php','验证码输入错误','1');
				}
			}else{
				$commonc->refreshto('login.php','请输入验证码','1');
			}
		}else{
			$commonc->refreshto('login.php','请输入密码','1');			
		}
	}else{
		$commonc->refreshto('login.php','请输入用户名','1');
	}
?>